<!-- 转床管理页 -->
<template>
  <!-- 面包屑 -->
  <div style="margin: 20px;">
    <el-breadcrumb separator="/" style="line-height:35px">
      <el-breadcrumb-item><span style="color: #7A7A7A;">服务管理</span></el-breadcrumb-item>
      <el-breadcrumb-item><span style="color: #7A7A7A;">床位管理</span></el-breadcrumb-item>
      <el-breadcrumb-item><span style="color: #0468FF;font-weight: bold">转床管理</span></el-breadcrumb-item>
    </el-breadcrumb>
  </div>

  <!-- 搜索栏 -->
  <el-card style="margin: 20px;height: 70px;border: 0" shadow="never">
    <el-form>
      <el-row :gutter="50">
        <el-col :span="8">
          <el-form-item label="老人姓名">
            <el-input placeholder="请输入老人姓名" v-model="searchForm.name"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="转床日期" style="">
            <el-date-picker
                type="date"
                placeholder="请选择日期"
                value-format="YYYY-MM-DD HH:mm:ss"
                format="YYYY-MM-DD"
                v-model="searchForm.createTime"
                @change="loadBed"
                style="width: 300px;"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item>
            <el-button @click="resetSearch">重置</el-button>
            <el-button type="primary" @click="loadBed">查询</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </el-card>

  <!-- 列表 -->
  <el-card style="margin:20px;border: 0" shadow="never">
    <el-table :data="currentTableData" height="550px"
              :row-style="{'height':'50px'}"
              :cell-style="{'color':'#000'}"
              :header-cell-style="{
                'background-color': '#f2f2f2',
                'color': '#000',
                'height':'50px'
              }">
      <el-table-column prop="id" label="档案编码" align="center" width="180"/>
      <el-table-column prop="name" label="老人姓名" align="center" width="100"/>
      <el-table-column prop="gender" label="性别" align="center" width="100"/>
      <el-table-column prop="roomNumber" label="入住房间" align="center" width="100"/>
      <el-table-column prop="originBed" label="原床位" align="center" width="100"/>
      <el-table-column prop="originBedPrice" label="原床位金额" align="center" width="100"/>
      <el-table-column prop="newBed" label="转入床位" align="center" width="100"/>
      <el-table-column prop="newBedPrice" label="转入床位金额" align="center" width="120"/>
      <el-table-column prop="createTime" label="转床时间" align="center" width="200"/>
      <el-table-column prop="reason" label="转床原因" align="center" width="400"/>

    </el-table>

    <!-- 分页组件 -->
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableData.length"
        style="margin-top: 20px;margin-left: 5px;"
    />
  </el-card>


</template>

<script setup>
import {onMounted, ref} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";
import qs from "qs";

//搜索栏表单
const searchForm = ref({name: '', createTime: ''})
//重置搜索栏
const resetSearch = () => {
  searchForm.value = {name: '', createTime: ''}
  loadBed()
}

//表格数据
const tableData = ref([]);
const currentTableData = ref([]) // 当前页显示的数据
const currentPage = ref(1)      // 当前页码
const pageSize = ref(10)        // 每页条数
//加载表格数据
const loadBed = () => {
  let data = qs.stringify(searchForm.value)
  axios.get(BASE_URL + '/v1/turnBed/select?' + data)
      .then((response) => {
        if (response.data.state == 2000) {
          tableData.value = response.data.data
          updateCurrentData()
        } else {
          ElMessage.error(response.data.message)
        }
      })
}
onMounted(() => {
  loadBed()
})

// 获取数据（示例）
const fetchData = async () => {
  // 这里替换为你的API请求
  // dataTable.value = await api.getData();

}

// 更新当前页数据
const updateCurrentData = () => {
  const start = (currentPage.value - 1) * pageSize.value
  const end = start + pageSize.value
  currentTableData.value = tableData.value.slice(start, end)
}

// 每页条数变化
const handleSizeChange = (val) => {
  pageSize.value = val
  updateCurrentData()
}

// 页码变化
const handleCurrentChange = (val) => {
  currentPage.value = val
  updateCurrentData()
}

// 生命周期钩子
onMounted(() => {
  fetchData()
})


</script>

<style scoped>

.el-dialog .el-input {
  width: 230px;
}
</style>